package com.rongshu.view.discovery.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.rongshu.view.base.BaseFragment;
import com.rongshu.view.base.BaseFragmentListener;
import com.rongshu.view.discovery.fragment.SearchResultAllFragment;
import com.rongshu.view.discovery.fragment.SearchResultArticleFragment;
import com.rongshu.view.discovery.fragment.SearchResultAuthorFragment;
import com.rongshu.view.home.bean.LabelResponse;

/**
 * created by zhengweis on 2018/11/1.
 * description：
 */
public class SearchResultPageAdapter extends FragmentPagerAdapter {
    String[] titles = {"综合", "文章", "用户"};
    private BaseFragmentListener listener;
    private LabelResponse.ResponseBean bean;
    public final static int MORE_ARTICLE = 1001;
    public final static int MORE_AUTHOR = 1002;

    public SearchResultPageAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setListener(BaseFragmentListener listener) {
        this.listener = listener;
    }

    public void setData(LabelResponse.ResponseBean bean) {
        this.bean = bean;
    }

    @Override
    public Fragment getItem(int position) {
        return createForNoExpand(position);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    private Fragment createForNoExpand(int position) {
        BaseFragment fragment = null;
        switch (position) {
            case 0:
                fragment = new SearchResultAllFragment();
                break;
            case 1:
                fragment = new SearchResultArticleFragment();
                break;
            case 2:
                fragment = new SearchResultAuthorFragment();
                break;
        }
        if (listener != null) {
            fragment.setCallback(new BaseFragmentListener() {
                @Override
                public void onCallBack(Object object) {
                    listener.onCallBack(object);
                }
            });
        }
        Bundle bundle = new Bundle();
        bundle.putSerializable("searchMsg", bean);
        fragment.setArguments(bundle);
        return fragment;
    }
}